package com.ewzj.bigdata.mvp.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.ewzj.bigdata.R;
import com.ewzj.bigdata.mvp.ui.widget.CardAdapterHelper;
import com.jess.arms.http.imageloader.glide.ImageConfigImpl;
import com.jess.arms.utils.ArmsUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Author:zhangjing
 * Time:2018/1/31  下午3:31
 * Name: this is BannerAdapter
 * Email:zhangjingworkmol@163.com
 */

public class BannerAdapter extends RecyclerView.Adapter<BannerAdapter.ViewHolder> {
    private List<String> mList = new ArrayList<>();
    private CardAdapterHelper mCardAdapterHelper = new CardAdapterHelper();

    public BannerAdapter(List<String> mList) {
        this.mList = mList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_banner_item, parent, false);
        mCardAdapterHelper.onCreateViewHolder(parent, itemView);
        return new ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {

        mCardAdapterHelper.onBindViewHolder(holder.itemView, position, getItemCount());
        ArmsUtils.obtainAppComponentFromContext(holder.itemView.getContext()).imageLoader().loadImage(
                holder.mImageView.getContext(), ImageConfigImpl.builder().imageView(holder.mImageView)
                .url(mList.get(position % mList.size())).build());

        holder.mImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ArmsUtils.snackbarText(""+ position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return Integer.MAX_VALUE;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public final ImageView mImageView;

        public ViewHolder(final View itemView) {
            super(itemView);
            mImageView = (ImageView) itemView.findViewById(R.id.imageView);
        }

    }

}